﻿using System.Collections.Generic;
using Pap.Data;
using Pap.Web.Utils;
using System.Collections;
using System;
using Pap.Data.LToS.Utils;
using Pap.Data.Abstraction.Utils;
using Microsoft.Practices.ServiceLocation;


namespace Pap.Web.Modules.Membership.ViewModel
{

    /// <summary>
    /// 
    /// </summary>
    public class AssociationsLinksViewModel : IViewModel
    {
        #region [Members]
        /// <summary>
        /// 
        /// </summary>
        private IAdministrationRepository _AdministrationRepository;
        #endregion

        #region [Functions]

        /// <summary>
        /// Initializes a new instance of the <see cref="AssociationsLinksViewModel"/> class.
        /// </summary>
        /// <param name="AdministrationRepository">The administration repository.</param>
        public AssociationsLinksViewModel(IAdministrationRepository AdministrationRepository)
        {
            this._AdministrationRepository = AdministrationRepository;
        }

        /// <summary>
        /// Find all Associations Links
        /// </summary>
        /// <returns></returns>
        public IEnumerable GetAllCommitteesURLs()
        {
            return this._AdministrationRepository.GetAllCommitteesURLs();
        }
        #endregion

        internal void UpdateCommitteesURLs(List<Guid> committeeIDs, List<string> URLs)
        {
            using (IUnitOfWork transaction = ServiceLocator.Current.GetInstance<IUnitOfWork>())
            {
                ICommitteesURL existingRec;
                for (int i = 0; i < committeeIDs.Count; i++)
                {
                    existingRec = _AdministrationRepository.GetCommittesURLByCommiteeID(committeeIDs[i]);
                    
                    if (!URLs[i].IsNullOrEmpty())
                        existingRec.CommitteeURL = URLs[i];
                    else
                        existingRec.CommitteeURL = null;
                }
                transaction.Commit();
            }
        }


        internal void CreateURLToNewCommittees()
        {
            _AdministrationRepository.CreateURLToNewCommittees();
        }
    }
}